<template>
	<view class="houseAcceptance">
		<view class="content" v-for="(item, i) in houseInfo" :key="i" v-if="!item.endTime">
			<view class="title">
				<text>房源地址: {{ item.houseAddress }}</text>
			</view>
			<view class="content-list">
				<text>房型: {{ item.roomType }}</text>
				<text>开工时间: {{ item.startTime }}</text>
			</view>
			<view class="content-list">
				<text>监理姓名: {{ item.supervisionName || '保密' }}</text>
				<text>工长姓名: {{ item.foremanName || '保密' }}</text>
			</view>
			<view class="content-list">
				<text>瓦工姓名: {{ item.bricklayerName || '保密' }}</text>
				<text>木工姓名: {{ item.carpenterName || '保密' }}</text>
			</view>
			<view class="content-list">
				<text>水电工姓名: {{ item.plumberName || '保密' }}</text>
				<text>油漆工姓名: {{ item.painterName || '保密' }}</text>
			</view>
			<view class="buttom">
				<text>竣工时间: {{ item.endTime || '未竣工' }}</text>
			</view>
			<view class="submitTest">
				<button class="mini-btn" type="default" size="mini" @click="submitAcceptance(item)">提交验收</button>
				<button class="mini-btn" type="default" size="mini" @click="confirmAcceptance(item)">确认验收</button>
			</view>
		</view>
		<view class="more" v-if="houseInfo.length === 0">没有信息</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			houseInfo: []
		}
	},
	onLoad() {
		let worker = 'bricklayerId'
		let userid = uni.getStorageSync('userInfo').typeLevel
		userid = userid.split(',')[0]
		userid = Number(userid)
		if (userid === 7) {
			worker = 'bricklayerId'
		} else if (userid === 8) {
			worker = 'carpenterId'
		} else if (userid === 9) {
			worker = 'plumberId'
		} else if (userid === 10) {
			worker = 'painterId'
		}
		const params = {
			[worker]: uni.getStorageSync('userInfo').id,
			page: 1,
			limit: 99999
		}
		this.init(params)
	},
	methods: {
		init(params) {
			this.$api.getHouseInfos(params)
				.then(res => {
					if (res.success) {
						this.houseInfo = res.rows
					} else {
						uni.showToast({ title: res.msg, icon: 'none' })
					}
				})
				.catch(err => {
					console.log('request fail', err)
				})
		},
		submitAcceptance(item) {
			uni.navigateTo({
			  url: '../acceptanceInfo/acceptanceInfo?houseInfoId=' + item.id + '&houseOwnerId=' + item.houseOwnerId
			})
		},
		confirmAcceptance(item) {
			uni.navigateTo({
			  url: '../acceptanceEnd/acceptanceEnd?houseInfoId=' + item.id + '&houseOwnerId=' + item.houseOwnerId
			})
		}
	}
}
</script>

<style lang="scss" scoped>
.houseAcceptance {
	.content {
		view {
			line-height: 50rpx;
		}
		margin: 20rpx;
		padding: 20rpx;
		box-shadow: 0 0 16rpx #999;
		border-radius: 10rpx;
		.title {
			font-weight: bold;
		}
		.content-list {
			display: flex;
			text {
				width: 50%;
			}
		}
	}
	.more {
		text-align: center;
		padding: 20rpx;
		font-size: 32rpx;
	}
	.submitTest {
		display: flex;
		justify-content: center;
	}
}
</style>
